home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / mawk10.zip / FPE_TEST < prev    next >
Text File  |  1991-10-05  |  2KB  |  90 lines

  1. #!/bin/sh
  2.  
  3. # tests if mawk has been compiled to correctly handle
  4. # floating point exceptions
  5. #
  6.  
  7. test1='BEGIN{ print 4/0 }'
  8.  
  9.  
  10. test2='BEGIN { 
  11.   x = 100
  12.   do { y = x ; x *= 1000 } while ( y != x )
  13.   print "loop terminated"
  14. }'
  15.  
  16. test3='BEGIN{ print log(-8) }'
  17.  
  18.  
  19. echo "testing division by zero"
  20. echo mawk "$test1"
  21. mawk "$test1"
  22. ret1=$?
  23. echo
  24.  
  25. echo "testing overflow"
  26. echo mawk "$test2"
  27. mawk "$test2"
  28. ret2=$?
  29. echo
  30.  
  31. echo "testing domain error"
  32. echo mawk "$test3"
  33. mawk "$test3"  > temp$$
  34. ret3=$?
  35. cat temp$$
  36. echo
  37.  
  38.  
  39. # the returns should all be zero or all 1
  40. # core dumps not allowed
  41.  
  42. echo
  43. echo ==============================
  44.  
  45. echo return1 = $ret1
  46. echo return2 = $ret2
  47. echo return3 = $ret3
  48.  
  49.  
  50. [ $ret1 -gt 128 ] && { echo test1 failed ; exception=1 ; }
  51. [ $ret2 -gt 128 ] && { echo test2 failed ; exception=1 ; }
  52. [ $ret3 -gt 128 ] && { echo test3 failed ; exception=1 ; }
  53.  
  54. [ "$exception" = 1 ] && { rm -f core temp$$ ; exit 1 ; }
  55.  
  56.  
  57. same=0
  58.  
  59. [ $ret1 = $ret2 ] && [ $ret2 = $ret3 ] && same=1
  60.  
  61.  
  62. if [ $same = 1 ]
  63.    then
  64.    if [ $ret1 = 0 ]
  65.       then 
  66.     echo results consistent: ignoring floating exceptions
  67.     if  grep -i nan temp$$  > /dev/null
  68.        then :
  69.        else
  70.          echo "but the library is not IEEE754 compatible"
  71.          echo "test 3 failed"
  72.          rm temp$$
  73.     fi
  74.       else echo results consistent: trapping floating exceptions
  75.    fi
  76.  
  77.    rm -f temp$$
  78.    exit 0
  79.  
  80.    else
  81.    echo results are not consistent
  82. echo 'return values should all be 0 if ignoring FPEs (e.g. with IEEE754)
  83. or all 1 if trapping FPEs
  84. '
  85.  
  86. rm -f temp$$
  87. exit 1
  88. fi
  89.  
  90.